const userinfo = require('../models/model/userInfo');

/**
 * 创建用户信息
 * @param {用户名} name 
 * @param {年龄} age 
 * @param {性别} sex 
 * @param {地址} adress 
 * @param {头像} avatar 
 * @param {介绍} Introduction 
 */
exports.addUserinfo = async (name = '', age = 0, sex = null, adress = '', avatar = '', Introduction = '', userId = '') => {
    if (!name) return;
    const ins = await userinfo.create({
        name,
        age,
        sex,
        adress,
        avatar,
        Introduction,
        userId
    });
    return ins.toJSON();
}

/**
 * 根据用户id删除用户信息
 * @param {用户id} userId 
 * @returns 返回受影响的条数
 */
exports.deleteUserinfo = async (userId) => {
    if (!userId) return;
    const ins = await userinfo.destroy({
        where: {
            userId
        }
    });
    return ins;
}

/**
 * 更新用户信息
 * @param {用户名} name 
 * @param {年龄} age 
 * @param {性别} sex 
 * @param {地址} adress 
 * @param {头像} avatar 
 * @param {介绍} Introduction 
 * @param {用户Id} userId 
 */
exports.updateUserinfo = async (name = '', age = 0, sex = null, adress = '', avatar = '', Introduction = '', userId = '') => {
    const ins = await userinfo.update(
        {
            name,
            age,
            sex,
            adress,
            avatar,
            Introduction
        },
        {
            where: {
                userId
            }
        }
    )
    return ins;
}
